package com.ideaaedi.log4j2.defender.properties;

import com.ideaaedi.log4j2.defender.defender.Log4j2MessageDefender;
import com.ideaaedi.log4j2.defender.strategy.DefenderStrategy;
import org.apache.logging.log4j.core.LogEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 脱敏配置项
 *
 * @author JustryDeng
 * @since 2021/7/21 1:15:15
 */
public class DefaultJsonProperties {

    /**
     * 当string类型字段的字段值是 一个json字符串时,是否对该内容中的敏感信息进行脱敏
     */
    private boolean hitStringValueIsJson = false;

    /** 脱敏的策略 以及 对应的脱敏字段集合 */
    private Map<DefenderStrategy, Set<String>> strategies;
    
    /**
     * 指定短路插件
     * <p>
     *     当shortCircuitPlugins中存在{@link Log4j2MessageDefender#support(LogEvent)}匹配的插件时，
     *     使用该插件进行脱敏，而不用脱敏器进行脱敏
     * </p>
     */
    private List<Log4j2MessageDefender> shortCircuitPlugins = new ArrayList<>();
    
    public boolean isHitStringValueIsJson() {
        return hitStringValueIsJson;
    }
    
    public void setHitStringValueIsJson(boolean hitStringValueIsJson) {
        this.hitStringValueIsJson = hitStringValueIsJson;
    }
    
    public Map<DefenderStrategy, Set<String>> getStrategies() {
        return strategies;
    }
    
    public void setStrategies(Map<DefenderStrategy, Set<String>> strategies) {
        this.strategies = strategies;
    }
    
    public List<Log4j2MessageDefender> getShortCircuitPlugins() {
        return shortCircuitPlugins;
    }
    
    public void setShortCircuitPlugins(List<Log4j2MessageDefender> shortCircuitPlugins) {
        this.shortCircuitPlugins = shortCircuitPlugins;
    }
    
    @Override
    public String toString() {
        return "DefaultJsonProperties{" +
                "hitStringValueIsJson=" + hitStringValueIsJson +
                ", strategies=" + strategies +
                '}';
    }
}